home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2329 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.rain.org!usenet
  2. From: "Guus Leeuw jr." <guusl@eiffel.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: When to use "->" vs "." when calling Member functions
  5. Date: Tue, 16 Jan 1996 19:14:21 -0800
  6. Organization: ISE Inc. http://www.eiffel.com
  7. Message-ID: <30FC698D.6D216C84@eiffel.com>
  8. References: <4dhea1$6v8@ornews.intel.com>
  9. NNTP-Posting-Host: @outback.eiffel.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b3 (X11; I; Linux 1.2.8 i586)
  14.  
  15. Thurman Miller wrote:
  16. > I'm confused, so please no harsh remarks :)
  17. > If I've got:
  18. > class Cfoo
  19. > {
  20. >         something * getptr();
  21. >         somethingelse* m_other;
  22. > }
  23. > something * foo::getptr()
  24. > {
  25. >         return m_other;
  26. > }
  27. > Now...if I'm in another class....
  28. >         Cfoo foo;
  29. >         somethingelse* = foo.getptr();
  30. > why doesn't the following work?
  31. >         somethingelse* = foo->getptr();
  32. > I get compile error about no "->" overloaded operator....
  33. > Can someone point out the obvious when I use one notation over
  34. > another?
  35. > TIA
  36. > Thurman
  37.  
  38. Okay, here we go.
  39.  
  40. When you write "foo->getptr()", you're actually writing
  41. "(*foo).getptr()". And that is where your problem is.
  42.  
  43. The selector (`xyz->abc') is used as a shorthand notation for
  44. `(*xyz).abc', and therefor can only be aplied to pointers to objects. As
  45. in:
  46.         Cfoo *foo;
  47.         somethingelse* = foo->getptr();
  48.  
  49. Hope this explains,
  50.     Guus Leeuw jr.
  51.